package com.taxshare.gateway.exception;


import cn.hutool.core.exceptions.ExceptionUtil;
import com.taxshare.gateway.constant.ResultConstant;
import com.taxshare.response.beans.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class BaseExceptionController {

    /**
     * 全局异常捕捉处理
     *
     * @param e 异常信息
     * @return
     */
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public Response errorHandler(Exception e) {
        //打印日志
        log.error("统一异常捕获", "Exception", e);
        //设置异常信息
        return Response.error(ResultConstant.RET_GAT_00000_CODE, ResultConstant.RET_GAT_00000_DESC, ExceptionUtil.getMessage(e));
    }

}
